﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using RabbitMQ.Client;

namespace EmitLog
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "localhost" };

            using(var connection = factory.CreateConnection())
            using (var channel=connection.CreateModel())
            {

                channel.ExchangeDeclare(
                    exchange: "logs", 
                    type: "fanout");

                //消息
                while(true)
                {
                    var message = Console.ReadLine();
                    var body = Encoding.UTF8.GetBytes(message);



                    channel.BasicPublish(exchange: "logs",      //交换器的名称为 logs，如果为空字符串表示默认或者名字缺省的交换器
                                        routingKey: "",         //消息通过指定的 routingkey 进行数据路由，发送接收通过该key指定数据，
                                        basicProperties: null,
                                        body: body);
                    Console.WriteLine(" [x] Sent {0}", message);
                }

            }
            Console.WriteLine(" Press [enter] to exit.");
        }
    }
}
